<template>
    <base-breadcrumb class="allPlan">
        <searchData :searchData="searchArr" @search="search"></searchData>
        <a-card :bordered="false">
            <b-table
                :scroll="{x:1376}"
                ref="table"
                :columns="columns"
                :request="loadData"
                :exportConfig="{use:true,select:'云筑网合同入库选中',all:'云筑网合同入库全部'}"
            >
                <template slot="prefix" slot-scope="ref">
                    <a-button type="primary" icon="plus" @click="handleEdit(null,1)"
                              v-btnPermission="'mm_009_add_01'">
                        新增
                    </a-button>
                </template>
                <span slot="index" slot-scope="text, record, index">{{ index + 1 }}</span>
                <template slot="auditStatusStr" slot-scope="text, record, index">
                    <list-status :status="record.auditStatus" :text="text"></list-status>
                </template>
                <template slot="operation" slot-scope="text, record, index">
                    <MoreButton>
                        <a @click="handleEdit(record, 3)">查看</a>
                        <template v-if="record.auditStatus === 'DRAFT' || record.auditStatus === 'REJECTED'">
                            <a @click="handleEdit(record, 2)">编辑</a>
                            <a @click="handleDel(record.id)">删除</a>
                        </template>
                    </MoreButton>
                </template>
            </b-table>
        </a-card>
    </base-breadcrumb>
</template>

<script>
import cloudBuildNetworkApi from '@/api/legal/branchContract/cloudBuildNetwork'
import { goodsDirectoryList, selectOption } from '@/api/material/goods/goods'
import SelectSubCompany from '@/components/Select/SelectSubCompany'
import SelectProject from '@/components/Select/SelectProject'

export default {
    name: 'cloudBuildNetworkIndex',
    data() {
        return {
            columns: [
                {
                    title: '所属分公司',
                    dataIndex: 'branchComName',
                    width: 150
                },
                {
                    title: '项目名称',
                    dataIndex: 'projectName',
                    width: 150
                },
                {
                    title: '云筑网合同入库编码',
                    dataIndex: 'yunzhuCode',
                    width: 160
                },
                {
                    title: '合同编号 ',
                    dataIndex: 'code',
                    width: 120

                },
                {
                    title: '合同名称',
                    dataIndex: 'name',
                    width: 120
                },
                {
                    title: '工程名称',
                    dataIndex: 'constructionTypeName',
                    width: 120
                },
                {
                    title: '合同相对方',
                    dataIndex: 'supplier',
                    width: 120
                },
                {
                    title: '合同价款',
                    dataIndex: 'contractPrice',
                    width: 120
                },
                {
                    title: '业务主管',
                    dataIndex: 'materialPeople',
                    width: 120
                },
                {
                    title: '状态',
                    dataIndex: 'auditStatusStr',
                    scopedSlots: { customRender: 'auditStatusStr' },
                    width: this.STATUS_WIDTH
                },
                {
                    title: '操作',
                    width: 200,
                    fixed: 'right',
                    scopedSlots: { customRender: 'operation' }
                }
            ],
            searchArr: [
                {
                    name: '所属分公司',
                    valueKey: 'branchCompanyId',
                    type: SelectSubCompany
                },
                // {
                //     name: '项目名称',
                //     type: SelectProject,
                //     valueKey: 'projectId'
                // },
                // 搜索框
                {
                    name: '云筑网合同入库编码',
                    type: 'input',
                    value: 'yunzhuCode'
                },
                {
                    name: '合同编号',
                    type: 'input',
                    value: 'code'
                },
                {
                    name: '合同名称',
                    type: 'input',
                    value: 'name'
                },
                {
                    name: '工程名称',
                    type: 'select',
                    value: 'constructionTypeId',
                    data: [],
                    request: () => selectOption({ type: 18 })
                },
                {
                    name: '合同相对方',
                    type: 'input',
                    value: 'counterParty'
                },
                {
                    name: '合同价款',
                    type: 'rangeInput',
                    value: 'contractPrice'
                },
                {
                    name: '业务主管',
                    type: 'input',
                    value: 'materialPeople'
                },
                {
                    name: '状态',
                    type: 'select',
                    value: 'auditStatus',
                    data: this.STATUS
                }
            ],
            loadData: (params) => {
                return cloudBuildNetworkApi.findListByMain({}, Object.assign(params, this.queryParam))
            },
            queryParam: {}
        }
    },
    methods: {

        search(val) {
            this.queryParam = val || {}
            this.$refs.table.getData(null, true)
        },
        handleDel(id) {
            let params = id ? [id] : this.selectId
            this.delList(cloudBuildNetworkApi.deleteByMain, () => {
                this.search()
            }, { ids: params })

        },
        handleEdit(record = {}, state) {
            this.$router.push({
                path: '/legal/branch-contract/cloud-build-network/add',
                query: {
                    id: record && record.id || '',
                    state: state
                }
            })
        }
    }
}
</script>
